package sms

import (
	"fmt"
	smsapi "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
	"github.com/alibabacloud-go/tea/tea"
)

type sms struct {
	client *smsapi.Client
}

func (c *sms) GetClient() *smsapi.Client {
	return c.client
}

// SendSMS 发送短信
func (c *sms) SendSMS(sendVO ISendVO) (*smsapi.SendSmsResponse, error) {
	sendRequest := &smsapi.SendSmsRequest{
		PhoneNumbers:  tea.String(sendVO.GetPhone()),
		SignName:      tea.String(sendVO.GetSignName()),
		TemplateCode:  tea.String(sendVO.GetTemplateCode()),
		TemplateParam: tea.String(sendVO.GetTemplateParam()),
	}

	resp, err := c.client.SendSms(sendRequest)
	if nil != err {
		return resp, err
	}

	if RespOK != *resp.Body.Code {
		return resp, fmt.Errorf("SendSMS error: Code: %v Msg: %v", *resp.Body.Code, *resp.Body.Message)
	}

	return resp, nil
}
